<template>
	<view class="preview-container">
		<view class="header-content">
			<view class="info-card">
				<text class="course-title">{{ courseName }}</text>
				<text class="content">内容要点：{{content}}</text>
				<text class="content">课程类型：{{classType }}</text>
				<text class="teacher">授课教师：{{ teacherName }}</text>

			</view>
		</view>
		<view v-if="loading" class="loading">
			<text>加载中...</text>
		</view>

		<view v-else class="preview-content">
			<!-- 调整按钮布局结构 -->
			<view class="button-group">
				<button @tap="previewFile" class="preview-btn">课件</button>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from "vue";
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		apigetCourseFiles,
		apiConvertPPTToImages
	} from "../../../api/apis";

	const fileUrl = ref('');
	const loading = ref(true);
	const courseId = ref('');
	const courseName = ref('');
	const teacherName = ref('');
	const content = ref('');
	const classType = ref('');
	const isPPT = ref(false);
	const pptImages = ref([]);
	onLoad((options) => {
		console.log("路由参数:", options);
		courseId.value = options.courseId || '';
		loadCourseFiles();
	});

	const loadCourseFiles = async () => {
		try {
			console.log("开始加载课程资料，CourseID:", courseId.value);
			const res = await apigetCourseFiles({
				courseId: courseId.value,
				headers: {
					'Cache-Control': 'no-cache' // 防止缓存导致跨域问题
				}
			});
			console.log("接口响应:", res);
			console.log(res.data.subject);
			if (res.code === 0) {
				// fileUrl.value = res.data.famous; 
				// console.log(fileUrl.value)
				courseName.value = res.data.subject || '';
				teacherName.value = res.data.teacher || '';
				classType.value = res.data.classType || '无';
				content.value = res.data.content || '暂无';
			} else {
				console.warn("未找到课件数据");
			}
		} catch (error) {} finally {
			loading.value = false;
		}
	};

	// 在script部分添加预览方法
	const previewFile = async () => {
		// 页面的跳转
		uni.navigateTo({
			url:`/pages/file-detail/file-detail?courseId=${courseId.value}`
		})
	}

	const goBack = () => {
		uni.navigateBack();
	};
</script>

<style lang="scss" scoped>
	.preview-container {
		min-height: 100vh;
		background: rgba(245, 247, 250, 0.98);
		backdrop-filter: blur(10px);
		padding: 0;
		padding-top: var(--status-bar-height, 44px);
	}

	/* 调整按钮布局样式 */
	.button-group {
		width: 100%;
		padding: 0 32rpx;
		margin-top: 40rpx;

		button {
			width: 100%;
			margin: 0;

			+button {
				margin-top: 30rpx;
			}
		}
	}

	.preview-btn {
		background: #007AFF;
		color: white;
		font-size: 32rpx;
		line-height: 90rpx;
		box-shadow: 0 5rpx 8rpx rgba(0, 0, 0, 0.1);
	}

	.preview-header {
		padding: 20rpx 30rpx;
		background-color: #fff;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
	}

	.info-card {
		background: #ffffff;
		margin: 24rpx 32rpx;
		padding: 32rpx;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.06);

		.course-title {
			display: block;
			font-size: 36rpx;
			font-weight: 600;
			color: #34495e;
			margin-bottom: 16rpx;
		}

		.teacher {

			font-size: 28rpx;
			color: #7f8c8d;
			margin-bottom: 16rpx;
		}

		.content {
			font-size: 28rpx;
			margin-bottom: 16rpx;
			display: block;
			color: #7f8c8d;
		}
	}

	.loading,
	.empty-state {
		text-align: center;
		padding: 40rpx;
		color: #666;
		font-size: 28rpx;
	}

	.preview-content {
		flex: 1;
		padding: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>